from pynput import mouse

def on_move(x, y):
    print(f'鼠标移动到({x},{y})位置')

def on_click(x, y, button, pressed):
    if pressed: # 是否按下鼠标
        status = '按下'
    else:
        status = '松开'

    print(f'{status}鼠标的位置在({x}, {y})')

    if not pressed:
        # 结束程序
        return False

def on_scroll(x, y, dx, dy):
    if dy < 0:
        status = '下'
    else:
        status = '上'
    print(f'向{status}滚动到({x},{y})')

with mouse.Listener(on_move=on_move,
                    on_click=on_click,
                    on_scroll=on_scroll) as listener:
    # 开启鼠标监听线程
    listener.join()
